﻿@model IEnumerable<tutors_clus.Models.annoucement>

@{
    ViewBag.Title = "Danh sách thông báo";
    Layout = "~/Views/Shared/_Layout_Private.cshtml";
    }
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/jquery-ui.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>
<div id="cleft">@Html.Partial("_menu_admin")</div>
<div id="cright">

<h3>Danh sách thông báo</h3>

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.title_ann)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.create_date_ann)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.file_attach_ann)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.writer_ann)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.detail_ann)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.status_ann)
        </th>
        <th></th>
    </tr>
    <tbody class="sort">
@foreach (var item in Model) {

    <tr rel="@item.id_ann">
        <td>
            @Html.DisplayFor(modelItem => item.title_ann)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.create_date_ann)
        </td>
        <td>
            <a href="~/Content/FileUpload_annou/@item.file_attach_ann">@item.file_attach_ann</a>
           @* @Html.ActionLink(item.file_attach_ann, "Download_annou", new {name=item.file_attach_ann })*@
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.writer_ann)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.detail_ann)
        </td>
       <td id="@item.id_ann">
          
            @if (item.status_ann == true)
            {
                @Ajax.ActionLink("tick", "Change_sta_annou", new {id = item.id_ann}, new AjaxOptions {InsertionMode=InsertionMode.Replace, UpdateTargetId = item.id_ann.ToString()},new { @class="true" })
            }
            else
            {
                 @Ajax.ActionLink("tick", "Change_sta_annou", new {id = item.id_ann}, new AjaxOptions {InsertionMode=InsertionMode.Replace, UpdateTargetId = item.id_ann.ToString()},new { @class="false" })
            }
        </td>
        <td>
            @Html.ActionLink("Sửa", "Edit_annou", new { id=item.id_ann }) |
            @Html.ActionLink("Xem chi tiết", "Detail_annou", new { id=item.id_ann}) |
            @Html.ActionLink("Xoá", "Delete_annou", new { id = item.id_ann }, new { onclick = "return confirm('Bạn có chắc muốn xóa không?');" })
            @*<input type="button" title="Xóa thông báo" value="Xóa" onclick="if (confirm('Bạn có chắc muốn xóa không?')) location.href='@Url.Action("Delete_annou", "Admin", new { id = item.id_ann })'" />*@
        </td>
    </tr>
       
}

 </tbody>
</table>
</div>
<script>
    $(document).ready(function() {
         currPos1 = "";
         currPos2 = "";
        //var currPos3 = "";

        $(".sort").sortable({
            start: function (event, ui) {
                currPos1 = ui.item.index();
            },
            update: function(event, ui) {
               
                currPos2 = ui.item.index();
                var id_cnnou =ui.item.attr('rel');
                $.ajax({
                   type: "POST",
                   url: '/Admin/UpdatePosition_Annou',
                   data: 'id_annou='+id_cnnou+'&&start='+ currPos1+'&&end='+currPos2

              })
            }

        }); 
    });
</script>